var EMI = {
	alertDialog: function(content) {
		Wind.css('artDialog');
		Wind.use("artDialog",function(){
		art.dialog({
					id: 'tips',
					content: content,
					title: false,
					noFn: false,
					width: 300,
					height: 70,
					time: 1.5,
					zIndex: 9999
				});
		});		
	},
	waitDialog: function(content) {
		Wind.css('artDialog');
		return Wind.use("artDialog",function(){
			art.dialog({
		    lock: true,
		    title: false,
		    noFn: false,
		    width: 300,
			height: 70,
		    background: '#666',
		    opacity: 0.7,
		    content: '<div><img src="/statics/images/waiting.gif"/>' + content + '</div>'
			});
		});	
	},
	optDialog: function(content) {
		Wind.css('artDialog');
		return Wind.use("artDialog",function(){
			art.dialog({
		    lock: true,
		    title: false,
		    noFn: false,
		    width: 450,
			height: 100,
		    background: '#666',
		    opacity: 0.7,
		    content: content 
			});
		});	
	},
	formFocus: function(obj) {
		obj.focus();
		var eleTop = obj.offset().top;
		var docHeight = $(window).height();
		var scrollTop = eleTop - (docHeight / 2) + (obj.height() / 2);
		$("html,body").animate({"scrollTop":scrollTop}, "fast");
	},
	formFlash: function(obj) {
		var $this = obj;
		var oBorder = $this.css("border");
		if (oBorder == undefined) {
			return;
		}
		var obg = $this.css("background");
		
		var i = 0, t = false;
		while(!t) {
			t = setInterval(function(){
				i++;
				if (i % 2 != 0) {
					$this.css("border", "0px solid #FF0000").css("background", "#ffd3d3").css("box-shadow", "0 0 10px rgba(255, 60, 60, 1)");
				} else {
					$this.css("border", oBorder).css("background", obg).css("box-shadow", "");
				}
				if(i >= 6){
					clearInterval(t);
					$this.css("border", oBorder).css("background", obg).css("box-shadow", "");
				}
			},200);
		}
	},
	formPrompt: function(obj, message) {
		this.formFocus(obj);
		this.formFlash(obj);
		this.alertDialog(message);
	},
	reloadCodeImg: function(id) {
	    document.getElementById(id).src='/captcha';
	},
	IsEmpty: function(fData) {
		return ((fData==null) || (fData.length==0) );
	},
	IsInteger: function(fData) {
		 //如果为空，返回true
	    if (this.IsEmpty(fData))
	        return false;
	    if ((isNaN(fData)) || (fData.indexOf(".")!=-1) || (fData.indexOf("-")!=-1))
	        return false;
	    
	    return true;
	},
	IsPlusNumeric: function(fData) {
		if (this.IsEmpty(fData))
	        return false;
	    if ((isNaN(fData)) || (fData.indexOf("-")!=-1))
	        return false;
	    return true;
	},
};


	
function check_mobile(mobile){
	var flag	=	false;
	var value	=	$.trim(mobile);
	myreg		=	/^(1[3|4|5|8|7][0-9]{9})$/
	if(myreg.test(value))	flag	=	true;
	return flag;
}


var iTime = 59;
var Account;
function RemainTime(){
	var iSecond,sSecond="",sTime="",btn=$("#code");
	btn.attr('disabled',true);
	if (iTime >= 0){
		iSecond = parseInt(iTime%60);
		iMinute = parseInt(iTime/60)
		if (iSecond >= 0){
			if(iMinute>0){
				sSecond = iMinute + "分" + iSecond + "秒";
			}else{
				sSecond = iSecond + "秒";
			}
		}
		sTime=sSecond;
		if(iTime==0){
			clearTimeout(Account);
			sTime='获取验证码';
			iTime = 59;
			btn.attr('disabled',false);
		}else{
			Account = setTimeout("RemainTime()",1000);
			iTime=iTime-1;
		}
	}else{
		sTime='没有倒计时';
	}
	btn.val(sTime);
}
function get_mobile_code(tel){
	if(!check_mobile(tel)){
		EMI.alertDialog("手机号码有误!"); return
	}
	RemainTime();
	$.post('/api/login/sms', {'mobile':tel}, function(msg) {
		if(msg==-1){
			EMI.alertDialog("您的操作过快!请稍后再试。"); return		
		}
	}
	
)}

(function($){
			$.fn.totop=function(opt){
				var scrolling=false;
				return this.each(function(){
					var $this=$(this);
					$(window).scroll(function(){
						if(!scrolling){
							var sd=$(window).scrollTop();
							if(sd>100){
								$this.fadeIn();
							}else{
								$this.fadeOut();
							}
						}
					});
					
					$this.click(function(){
						scrolling=true;
						$('html, body').animate({
							scrollTop : 0
						}, 500,function(){
							scrolling=false;
							$this.fadeOut();
						});
					});
				});
			};
		})(jQuery); 
$("#backtotop").totop();
$(".weixin2").hover(function () {
    $(this).find(".qrcode").show();
}, function () {
    $(this).find(".qrcode").hide();
});

$("#main-menu").find(".sub h2").on("click",function(e) {
	if($(this).parent().hasClass("active")) {
		$(this).parent().removeClass("active");
		return false;
	}
	$(this).parent().toggleClass("active");

});


